package pl.edu.mimuw.irs.rcp.controller.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.ui.part.EditorPart;

public class SaveHandler extends AbstractHandler {

	// *** Attributes

	// *** Methods

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IEvaluationContext evaluationContext = (IEvaluationContext) event.getApplicationContext();
		EditorPart editor = (EditorPart) evaluationContext.getVariable("activeEditor");
		if (editor != null && editor.isDirty()) {
			editor.doSave(new NullProgressMonitor());
		}
		return null;
	}
}
